package com.qsmx.store.app.main;

import android.os.Bundle;
import android.text.Html;
import android.view.View;

import androidx.annotation.Nullable;

import com.qsmx.store.app.R;
import com.qsmx.store.app.databinding.DelegateHomeBinding;
import com.qsmx.store.core.fusion.FusionPre;
import com.qsmx.store.app.util.ApkManager;
import com.qsmx.store.core.delegates.AtmosDelegate;
import com.qsmx.store.core.util.storage.AtmosPreference;

public class HomeDelegate extends AtmosDelegate {

    private DelegateHomeBinding mBinding;

    @Override
    public Object setLayout() {
        return R.layout.delegate_home;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        mBinding = DelegateHomeBinding.bind(rootView);
        mBinding.tvAppInfo.setText(Html.fromHtml(String.format(getString(R.string.app_info), AtmosPreference.getCustomStringPre(FusionPre.APP_ELM_INFO), ApkManager.getVersionName(getContext()))));

        mBinding.btnMachineInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new MachineInfoDelegate());
            }
        });

        mBinding.btnAppPackageManager.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new ApkManagerDelegate());
            }
        });

        mBinding.btnNetTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new NetTestDelegate());
            }
        });

        mBinding.btnUpDownload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new UploadDelegate());
            }
        });
        mBinding.btnHardWareTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().start(new UploadDelegate());
            }
        });

        mBinding.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().pop();
            }
        });
    }
}
